package com.djinquan.common.method;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Desc:
 * @Group:美的集团-营销系统-技术组
 * @Author dengjq15
 * @Date 2023/7/26
 */
public class CustomerApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
    //private static Logger logger = LoggerFactory.getLogger(CustomerApplicationContextInitializer.class);

    public CustomerApplicationContextInitializer() {
    }

    public void initialize(ConfigurableApplicationContext applicationContext) {
        ResourcePropertySource propertySource = null;

        try {
            propertySource = new ResourcePropertySource("classpath:config/dubbo.properties");
        } catch (IOException var4) {
            //logger.error("properties is not exists");
        }

        applicationContext.getEnvironment().getPropertySources().addFirst(propertySource);
        /*
        //下面代码可以修改原配置文件的值，扩展:可以通过applicationContext.getEnvironment().getPropertySources()获取配置文件的键值
        String propertyName = "dubbo.url";
        Map<String,Object> map = new HashMap<>();
        map.put(propertyName,"http://www.baidu.com");
        MapPropertySource mapPropertySource = new MapPropertySource(propertyName,map);
        applicationContext.getEnvironment().getPropertySources().addFirst(mapPropertySource);*/
    }
}
